<template>
	<view class="ep-search">
		<view class="searchbox_l">
			<view :style="{borderRadius:radius+'px'}" class="ep-search-box" @click="searchClick">
				<!-- #ifdef MP-ALIPAY -->
				<view class="iconfont icon-sousuo">
				</view>
				<!-- #endif -->
				<!-- #ifndef MP-ALIPAY -->
				<image class="ep-search-box-icon-search" :src=" icosearch " type="search"></image>
				<!-- #endif -->
				<input v-if="show" :focus="showSync" :placeholder="placeholder" @confirm="confirm" class="ep-search-box-search-input"
				 confirm-type="search" type="text" v-model="searchVal" />
				<text v-else class="ep-search-text-placeholder">{{ placeholder }}</text>
				<view v-if="show && (clearButton==='always'||clearButton==='auto'&&searchVal!=='')" class="ep-search-box-icon-clear">
					<uni-icons color="#999999" class="" size="24" type="clear" />
				</view>
				<view @click="cancel" class="ep-search-cancel" v-if="show">
					<uni-icons color="#999" type="closeempty" size="30"></uni-icons>
				</view>
			</view>
		</view>
		<!-- <view class="searchbox_r">
			<image class="ico-video" :src="icovideo" @click="tovideo(item)"></image>
		</view> -->
	</view>
</template>

<script>
	import uniIcons from "../uni-icons/uni-icons.vue";
	export default {
		name: "epSearch",
		components: {
			uniIcons
		},
		props: {
			placeholder: {
				type: String,
				default: "搜索"


			},
			radius: {
				type: [String,Number],
				default: 100
			},
			clearButton: {
				type: String,
				default: "auto"
			}
		},
		data() {
			return {
				show: false,
				showSync: false,
				searchVal: "",
				icovideo: '/static/img/epvideo.png',  //.epvideo,
				icosearch: '/static/img/epsearch.png',  //.epsearch,
				item:'',
			}
		},
		watch: {
			searchVal() {
				this.$emit("input", {
					value: this.searchVal
				})
			}
		},
		onLoad() {},
		methods: {
			searchClick() {
				uni.navigateTo({
					url: '../search/search?type=post',
				})
				this.searchVal = ""
				this.show = false;
				this.$nextTick(() => {
					this.showSync = true;
				})
			},
			clear() {
				this.searchVal = ""
			},
			tovideo(item){
				this.$emit('click');
				this.$mRouter.push({
					route: this.$mRoutesConfig.userMyLearn,
					query: {
					}
				})
			},
			cancel() {
				this.$emit("cancel", {
					value: this.searchVal
				});
				this.searchVal = ""
				this.show = false
				this.showSync = false
				// #ifndef APP-PLUS
				uni.hideKeyboard()
				// #endif
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord()
				// #endif
			},
			confirm() {
				// #ifndef APP-PLUS
				uni.hideKeyboard();
				// #endif
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord()
				// #endif
				this.$emit("confirm", {
					value: this.searchVal
				})
			}
		}
	};
</script>

<style lang="scss">
	.ep-search {
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		justify-content: space-between;
		align-items: center;
		padding: 23rpx 30rpx 0rpx 30rpx;
		
	}

	.searchbox_l {
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		width: 100%;
	}

	.searchbox_r {
		display: flex;
		flex-direction: row-reverse;
		flex-wrap: nowrap;
		width: 10%;
	}

	.ico-video {
		display: flex;
		width: 45rpx;
		height: 45rpx;
	}

	.ep-search-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		overflow: hidden;
		position: relative;
		flex: 1;
		justify-content: flex-start;
		flex-direction: row;
		align-items: center;
		height: 56rpx;
		border-width: 0;
		border-style: solid;
		border-color: #e5e5e5;
		border-radius: 30rpx;
		background: #eee;
	}

	.ep-search-box-icon-search {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		width: 35rpx;
		height: 35rpx;
		justify-content: center;
		align-items: center;
		color: #808080;
		margin: 0 20rpx 0 30rpx
	}

	.ep-search-box-search-input {
		flex: 1;
		font-size: 28rpx;
		color: #333;
	}

	.ep-search-box-icon-clear {
		align-items: center;
		line-height: 48rpx;
		padding: 0 10rpx 0 10rpx;
		display: none;
	}

	.ep-search-text-placeholder {
		font-size: 28rpx;
		color: #b7b7b7;
		margin-left: 10rpx;
	}

	.ep-search-cancel {
		font-size: 28rpx;
		color: #b7b7b7;
		margin-right: 10rpx;
	}
</style>
